//
//  ZHRTRequestFailureShowViewOrDetail.m
//  ZHRTXinDaiLeague
//
//  Created by 胡志军 on 16/3/17.
//  Copyright © 2016年 胡志军. All rights reserved.
//

#import "ZHRTRequestFailureShowViewOrDetail.h"
#import "UIImage+GIF.h"
#define backGroundcolor [UIColor colorWithRed:249.0/255.0 green:249.0/255.0 blue:249.0/255.0 alpha:1]

@interface ZHRTRequestFailureShowViewOrDetail ()

@end

@implementation ZHRTRequestFailureShowViewOrDetail


+ (void)showRequestFailureForView:(UIView *)view  target:(id)target action:(SEL)action type:(NSInteger)type {
    
    [self showNoDataForView:view bigImage:@"notNowork" text:@"网络出问题了~请查看网络设置" btnImage:@"reload" target:target action:action type:type];
    
}


+ (void)showViewDetail:(NSString *)text view:(UIView *)selfView {
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 270, 40 * kScreenH / 480)];
    view.backgroundColor = [UIColor grayColor];
    view.center = selfView.center;
    CGRect rect = view.frame;
    rect.origin.y -= 124;
    view.frame = rect;
    view.layer.cornerRadius = 5;
    [selfView addSubview:view];
    
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 270, 40 * kScreenH / 480)];
    label.text = text;
    label.adjustsFontSizeToFitWidth = YES;
    label.font = [UIFont systemFontOfSize:16];
    label.numberOfLines = 0;
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor whiteColor];
    [view addSubview:label];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [view removeFromSuperview];
    });
          });
    
}

+ (void)showViewDetail:(NSString *)text view:(UIView *)selfView target:(id)target action:(SEL)action {
    
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 270, 30 * kScreenH / 480)];
    view.backgroundColor = [UIColor grayColor];
    view.center = selfView.center;
    CGRect rect = view.frame;
    rect.origin.y -= 124;
    view.frame = rect;
    view.layer.cornerRadius = 5;
    [selfView addSubview:view];
     
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 270, 30 * kScreenH / 480)];
    label.text = text;
    label.adjustsFontSizeToFitWidth = YES;
    label.font = [UIFont systemFontOfSize:16];
    
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor whiteColor];
    [view addSubview:label];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        [view removeFromSuperview];
        [target action];
    });
}

+ (void)showProgressHUDWithInView:(UIView *)view type:(NSInteger)type {
    
    UIImageView *imgView = [[UIImageView alloc] init];
    if (type == 1) {
        
        imgView.frame = CGRectMake((view.frame.size.width - 100) / 2 , (view.frame.size.height - 40) / 2  , 100, 40);
    }else if (type == 0) {
        
         imgView.frame = CGRectMake((view.frame.size.width - 100) / 2 , (view.frame.size.height - 40) / 2  - 64, 100, 40);
        
    }

    imgView.image = [UIImage sd_animatedGIFNamed:@"lodingGif"];
    [view addSubview:imgView];
}


+ (void)showNoDataForView:(UIView *)view imageNamed:(NSString *)imageNamed text: (NSString *)text type:(NSInteger)type {
    UIView * back = [[UIView alloc] initWithFrame:kScreenB];
    back.backgroundColor = backGroundcolor;
    [view addSubview:back];
    UIView * backView = [[UIView alloc] init];
   
    if (type == 0) {
        
        backView.frame = CGRectMake((kScreenW - 297 /2) /2, 100 * kscale, 297 /2, 306/2);
    } else {
        backView.frame = CGRectMake((kScreenW - 297 /2) /2, 100 * kscale + 64, 297 /2, 306/2);
    }
     UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake( 0, 0, 297 /2, 306/2)];
    imageView.image = [UIImage imageNamed:imageNamed];
    [backView addSubview:imageView];
    [back addSubview:backView];
    
    
    UILabel * title = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(backView.frame) + 30, kScreenW, 20)];
    title.text = text;
    [view addSubview:title];
    title.textColor = kColorRGB(153, 153, 153);
    title.font = [UIFont systemFontOfSize:14];
    title.textAlignment = NSTextAlignmentCenter;
    
}

+ (void)showNoDataForView:(UIView *)view bigImage:(NSString *)bigImage text:(NSString *)text btnImage:(NSString *)btnImage target:(id)target action:(SEL)action type:(NSInteger)type  {
    
    
    UIView * back = [[UIView alloc] initWithFrame:kScreenB];
    back.backgroundColor = backGroundcolor;
    [view addSubview:back];
    UIView * backView = [[UIView alloc] init];
    
    if (type == 0) {
        
        backView.frame = CGRectMake((kScreenW - 294 /2) /2, 100 * kscale, 294 /2, 313/2);
    } else {
        backView.frame = CGRectMake((kScreenW - 294 /2) /2, 100 * kscale + 64, 294 /2, 313/2);
    }
    
    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake( 0, 0, 294 /2, 313/2)];
    imageView.image = [UIImage imageNamed:bigImage];
    [backView addSubview:imageView];
    [back addSubview:backView];
    
    
    UILabel * title = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(backView.frame) + 30, kScreenW, 20)];
    title.text = text;
    [view addSubview:title];
    title.textColor = kColorRGB(153, 153, 153);
    title.font = [UIFont systemFontOfSize:14];
    title.textAlignment = NSTextAlignmentCenter;

    UIButton * btn = [[UIButton alloc] initWithFrame:CGRectMake((view.frame.size.width - 150)/ 2, CGRectGetMaxY(title.frame) + 30, 150, 37)];
    
    [btn setImage:[UIImage imageNamed:btnImage] forState:UIControlStateNormal];
    [view addSubview:btn];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
}
@end
